<template>
  <div class="autumn-container">
    <!-- 面包 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/dashboard' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/system/dict/customList' }">字典列表</el-breadcrumb-item>
      <el-breadcrumb-item>字典信息</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片 -->
    <div class="autumn-center">
      <div class="edit-form">
        <el-form ref="editFormRef" size="large" label-width="90px" disabled :model="editForm">
          <el-row>
            <el-col :span="12">
              <el-form-item label="上级" prop="parentId">
                <autumn-tree-select :data="treeDicts" v-model="editForm.parentId" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="标识" prop="code">
                <el-input v-model="editForm.code" :disabled="editForm.id ? true : false" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="名称" prop="name">
                <el-input v-model="editForm.name" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="排序" prop="sort">
                <el-input-number v-model="editForm.sort" :min="1" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注" prop="remark">
                <el-input type="textarea" resize="none" v-model="editForm.remark" />
              </el-form-item>
            </el-col>
          </el-row>

        </el-form>

        <div class="form-foot-button">
          <el-button @click="cancel">返回</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, reactive, nextTick } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { $convertTree } from 'src/util/tools'
import { listDict, viewDict } from 'src/api/system/dict'

const route = useRoute()
const router = useRouter()

const treeDicts = ref<Array<any>>([])
listDict({ isSys: 0 }).then(({ data }) => {
  treeDicts.value = $convertTree(data)
})

const editForm = reactive({
  id: '',
  parentId: '',
  code: '',
  name: '',
  sort: 1,
  isSys: 0,
  remark: ''
})
if (route.query.id) {
  const id = route.query.id as string
  viewDict(id).then(({ data }) => {
    Object.assign(editForm, data)
  })
}

const cancel = () => {
  router.push('/system/dict/customList')
}

</script>

<style lang="scss" scoped></style>
